package com.atguigu.demo.importdata;

import com.atguigu.eduservice.EduApplication;
import com.atguigu.eduservice.entity.Items;
import com.atguigu.eduservice.entity.TbDcUser;
import com.atguigu.eduservice.entity.ZxbApply;
import com.atguigu.eduservice.entity.zhonghan.CustomerContacts;
import com.atguigu.eduservice.entity.zhonghan.Customers;
import com.atguigu.eduservice.service.*;
import com.atguigu.eduservice.service.ZxbApplyService_base;
import com.atguigu.eduservice.service.slave_dataserver.QcZxbApplyService;

import com.atguigu.eduservice.service.slave_dataserver.QianchengItemsService;
import com.atguigu.eduservice.service.zhonghan.*;

import com.atguigu.eduservice.service.zhonghan.qiancheng.CustomerContactsBaseService;
import com.atguigu.eduservice.service.zhonghan.qiancheng.QC_CustomersService_base;
import com.atguigu.eduservice.utils.ExcelCommon;
import com.atguigu.eduservice.utils.ExcelExport;
import com.atguigu.eduservice.utils.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
import java.util.*;


/**
 * @author
 * @since 2018/12/13
 *
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = EduApplication.class)

@Slf4j
//@MapperScan("com.atguigu.eduservice.mapper")
public class Zxb_copydata {
    //@Autowired
    //TbDcUserMapper tbDcUserMapper;
    @Autowired
    private TbDcUserService tbDcUserService;
    @Autowired
    private
    ItemsService itemsService;

    @Autowired
    private
    QianchengItemsService qianchengItemsService;


    @Autowired
    private
    CustomersService customersService;
    @Autowired
    private
    CustomerContactsService customerContactsService;

    @Autowired
    private
    QcZxbApplyService qczxbApplyService;

    @Autowired
    private
    ZxbApplyService zxbApplyService;

    @Autowired
    private
    ZxbApplyService_base zxbApplyServicebase;
//    @Autowired
//    //private
//    //Zh_CustomersService_base zhCustomersServiceBase;

    @Autowired
    private
    QC_CustomersService_base qcCustomersServiceBase;



    @Autowired
    private
    ZhCustomerService zhcustomerBaseService;

    @Autowired
    private
    CustomerContactsBaseService customerContactsBaseService;

    @Autowired
    private
    ZhCustomerContactsBaseService zhcustomerContactsBaseService;







    @Test
    public void zxbapply_db() {
        QueryWrapper<ZxbApply> wrapper=new QueryWrapper<>();
        wrapper.select("top 1000 *")
                .orderByDesc("created");
        List<ZxbApply> zxbApplyList=qczxbApplyService.list(wrapper);
        for(int i=0;i<zxbApplyList.size();i++){
            ZxbApply zxbApply=zxbApplyList.get(i);
            QueryWrapper<ZxbApply> wrapper1=new QueryWrapper<>();
            if (!zxbApply.getJkmc().equals("非LC限额申请")) continue;
            wrapper.eq("corpSerialNo",zxbApply.getCorpSerialNo());

            int count=zxbApplyService.count(wrapper1);
            if (count>0)
            {
                UpdateWrapper<ZxbApply> wrapper_del=new UpdateWrapper<>();
                wrapper_del.eq("corpSerialNo",zxbApply.getCorpSerialNo());
                zxbApplyService.remove(wrapper_del);
                System.out.println("正在删除"+ zxbApply.getCorpSerialNo()+"成功");
            }
                zxbApplyService.save(zxbApply);
                System.out.println("正在保存"+ zxbApply.getJksm()+"成功");


        }
        //System.out.println(zxbApplyList);


    }






    //CustomerBank","CustomerContacts","CustomersShippingTo","Customers_Logistics","CustomersBillTo","CustomersExpresscor");






    @Test
    public void testmd5(){
        String password="123456";
        String recordid="58A1FED1-EE57-4DEC-A00F-F6541F4644F8";
        recordid=recordid.replaceAll("-", "");
        //System.out.println(recordid);
        //String md5_value= SecureUtil.MD5Encode(String.format("[Password][RecordID][%s][%s]",password,recordid));

        //String md5_value=SecureUtil.MD5Encode(recordid+password);
        String md5_value= SecureUtil.MD5Encode(String.format("Password:%sRecordID:%s",password,recordid));
        System.out.println(md5_value);
    }

    @Test
    public void export_excel() throws Exception{
        QueryWrapper<Items> wrapper=new QueryWrapper<>();
        wrapper.select("top 100 *")
                .orderByDesc("created");

      List<Items>  itemsList=itemsService.list(wrapper);
        ExcelExport excelExport=new ExcelExport();
      String str=excelExport.exportitem("d:\\1.xlsx",itemsList);

//        QueryWrapper<Items> wrapper1=new QueryWrapper<>();
//        wrapper.select("top 100 *")
//                .orderByDesc("created");

        List<Items>  itemsList1=qianchengItemsService.list(wrapper);
        String str1=excelExport.exportitem("d:\\qiancheng-1.xlsx",itemsList1);
        System.out.println(str);
       System.out.println(str1);

    }

    @Test

    public void importexcel() throws IOException, ClassNotFoundException {
        String filePath ="D:\\intersky\\前程\\工作\\user.xlsx";
        Set<String> key1= new HashSet<>();
        HashMap<String,Object> hashMap = ExcelCommon.getProxyPojoValue(new TbDcUser(),key1);


        //        Class c = Class.forName("com.atguigu.eduservice.entity.TbDcUser"); //要包名+类名
//
//        Field[] fields = c.getDeclaredFields();//拿到数据成员
//        List<String> fieldlist=new ArrayList<>();
//
//        for( Field f : fields ){
//            if (!f.getName().equals("serialVersionUID"))
//                fieldlist.add(f.getName());
//
//        }



    }
    @Test
    public void listoject() throws ClassNotFoundException {
        Class c = Class.forName("com.atguigu.eduservice.entity.TbDcUser"); //要包名+类名
        Set<String> key1= new HashSet<>();
        // 定义修改的值(后期可做成动态)
        key1.add("brokerUserId");
        // 定义主键id
        key1.add("custlockid");
        HashMap<String,Object> hashMap = ExcelCommon.getProxyPojoValue(new TbDcUser(),key1);
        System.out.println(hashMap);

//        Field[] fields = c.getDeclaredFields();//拿到数据成员
//        List<String> fieldlist=new ArrayList<>();
//
//        for( Field f : fields ){
//            if (!f.getName().equals("serialVersionUID"))
//                fieldlist.add(f.getName());
//
//        }
//         System.out.println(fieldlist);
    }


}
